﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using XMLGener.Utils;

namespace XMLGener.Data
{
    /// <summary>
    /// This class is used for keeping restrictions, that
    /// module can accept.
    /// </summary>
    public class XModuleRestrictions
    {
        /// <summary>
        /// Constuctor, which will parse restrictions
        /// from XML Element.
        /// </summary>
        /// <param name="moduleDefinition"></param>
        public XModuleRestrictions(XmlElement moduleDefinition)
        { 
            if (moduleDefinition == null)
                return;
            XmlElement el = XMLUtils.getSubElement(moduleDefinition, "type");
            if (el != null)
            {
                dataType = el.InnerText;
                if (string.IsNullOrEmpty(dataType.Trim()))
                    dataType="any";
            }
            el = XMLUtils.getSubElement(moduleDefinition,"acceptrestriction");
            string restrName = null;
            while (el!=null)
            {
                restrName = el.InnerText.ToLower();
                switch(restrName)
                {
                    case "length": length = true; break;
                    case "minlength": minLength = true; break;
                    case "maxlength": maxLength = true; break;
                    case "mininclusive": minInclusive = true; break;
                    case "maxinclusive": maxInclusive = true; break;
                    case "minexclusive": minExclusive = true; break;
                    case "maxexclusive": maxExclusibe = true; break;
                    case "pattern": pattern = true; break;
                    case "enumeration": enumeration = true; break;
                }
                el = XMLUtils.getNextElement(el,"acceptrestriction");
            }
            
        }

        /// <summary>
        /// Data type
        /// </summary>
        public string dataType = "any";

        /// <summary>
        /// Length restriction can be accepted
        /// </summary>
        public bool length = false;

        /// <summary>
        /// Minimal length restriction can be accepted
        /// </summary>
        public bool minLength = false;

        /// <summary>
        /// Maximal length restriction can be accepted
        /// </summary>
        public bool maxLength = false;

        /// <summary>
        /// Minimal inclusive number restriction can be accepted
        /// </summary>
        public bool minInclusive = false;

        /// <summary>
        /// Maximal inclusive number restriction can be accepted
        /// </summary>
        public bool maxInclusive = false;

        /// <summary>
        /// Minimal exclusive number restriction can be accepted
        /// </summary>
        public bool minExclusive = false;

        /// <summary>
        /// Maximal exclusive number restriction can be accepted
        /// </summary>
        public bool maxExclusibe = false;
        
        /// <summary>
        /// Pattern restriction can be accepted
        /// </summary>
        public bool pattern = false;
        
        /// <summary>
        /// Enumeration restriction can be accepted
        /// </summary>
        public bool enumeration = false;
            


    }
}
